package cn.qrx.gateway.bind;

import cn.qrx.gateway.seesion.GatewaySession;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;
import java.util.Map;

/**
 * @Author: 屈燃希
 * @Date:   2025/10/15
 * @Version: V1.0
 * @Description:
 */
public class MapperProxy implements MethodInterceptor {

    private Logger logger = LoggerFactory.getLogger(MapperProxy.class);

    private GatewaySession gatewaySession;
    private final String uri;

    public MapperProxy(GatewaySession gatewaySession, String uri) {
        this.gatewaySession = gatewaySession;
        this.uri = uri;
    }

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        MapperMethod linkMethod = new MapperMethod(uri, gatewaySession.getConfiguration());

        logger.info("执行原方法：{},{}",method.getName(),args);
        return linkMethod.execute(gatewaySession, (Map<String, Object>) args[0]);
    }

}
